{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF1"
test("0AF1 (write_int_to_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\cleo_test_file.ini"

function tests
    before_each(@cleanup)
    after_each(@cleanup)

    it("should fail to overwrite file", test1)
    it("should fail to overwrite directory", test2)
    it("should create new file", test3)
    it("should add to existing file", test4)
    it("should overwrite value", test5)
    return
    
    :cleanup
        delete_file {path} Test_Path
    return
    
    function test1
        write_int_to_ini_file {value} 42 {path} "gta_sa.exe" {section} "test" {key} "test"
        assert_result_false()
    end
    
    function test2
        write_int_to_ini_file {value} 42 {path} "cleo" {section} "test" {key} "test"
        assert_result_false()
    end
    
    function test3
        does_file_exist {path} Test_Path
        assert_result_false()
        
        write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
        assert_result_true()
        
        does_file_exist {path} Test_Path
        assert_result_true()
        
        int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test"
        assert_eq(value, 42)
    end
    
    function test4
        does_file_exist {path} Test_Path
        assert_result_false()
    
        write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "testA"
        assert_result_true()
        
        write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "testB"
        assert_result_true()
        
        int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "testA"
        assert_eq(value, 42)
        
        value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "testB"
        assert_eq(value, 50)
    end
    
    function test5
        does_file_exist {path} Test_Path
        assert_result_false()
    
        write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
        assert_result_true()
        
        write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "test"
        assert_result_true()
                
        int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test"
        assert_eq(value, 50)
    end

end
